#define MAGNET 23
#define REED 24

void setup() {
  pinMode(MAGNET, OUTPUT);
  pinMode(REED, INPUT);
  Serial.begin(9600);
}

void loop() {
  unsigned long starttime, endtime;
  starttime = millis();
  digitalWrite(MAGNET, HIGH);
  Serial.println("MAGNET ON");
  while(digitalRead(REED) == LOW);
  
  endtime = millis();
  digitalWrite(MAGNET, LOW);
  Serial.println(starttime - endtime);
  delay(3000);
}
